home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / Thread Manager Extension 2.0.1 / ThreadUtilities / SnakesWithSemaphores / Threads.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-03  |  6.7 KB  |  190 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Threads.h
  3.  
  4.     Contains:    External Interface to Thread Manager
  5.  
  6.     Written by:    David Harrison, Eric Anderson
  7.  
  8.     Copyright:    © 1991-1993 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.                 1/28/93        ewa        Made all error codes end with 'Err'. All errors are now
  13.                                     of the form: xxxErr
  14.                 1/27/93        ewa        Added GetDefaultThreadStackSize & ThreadCurrentStackSpace
  15.                                     information routines
  16.                 1/26/93        ewa        Added SetThreadStateEndCritical routine to help thread synchronization
  17.                 1/13/93        ewa        Put preemption quantum adjustment support into private header
  18.                 12/23/92    ewa        Added support for system wide preemption quantum adjustment
  19.                 12/22/92    ewa        User must now specify the required stack to use for their threads,
  20.                                     however, if they pass in zero we will provide them with a default size
  21.                 12/22/92    ewa        Added thread termination proc support
  22.                                     fixed param count in interface glue
  23.                 12/21/92    ewa        Added kFPUNotNeeded as a thread option
  24.                 7/31/92        ewa        Added Gestalt selector constants.
  25.         <4>        7/29/92        ewa        changed InterruptedSyncThreadID to InterruptedCoopThreadID.
  26.         <3>        7/15/92        ewa        Added calls to support interrupt time thread state manipulation.
  27.         <2>        7/14/92        ewa        Add callbacks to the debugger for birth, death and schedule.
  28.         <1>        7/13/92        ewa        added real error nums, changed CreateThreads to CreateThreadPool,
  29.                                      changed kToolbox & kAsync thread defines to be kCoop & kPremp.
  30.         <0>        4/19/91        DFH        New Today.
  31.  
  32. */
  33.  
  34. #ifndef __THREADS__
  35. #define __THREADS__
  36.  
  37. #include <Memory.h>
  38.  
  39. /* Thread Gestalt Selectors */
  40. enum {
  41. #define gestaltThreadAttr    'thds'            /* Thread Manager attributes */
  42.     
  43.     gestaltThreadsPresent = 0                /* bit true if Thread Mgr is present */
  44. };
  45.  
  46. /* Thread states */
  47. typedef unsigned short            ThreadState;
  48. #define kReadyThreadState        ((ThreadState) 0)
  49. #define kStoppedThreadState        ((ThreadState) 1)
  50. #define kRunningThreadState        ((ThreadState) 2)
  51.  
  52. /* Thread environment characteristics */
  53. typedef void*    ThreadTaskRef;
  54.  
  55. /* Thread characteristics */
  56. typedef unsigned long            ThreadStyle;
  57. #define kCooperativeThread        (1<<0)
  58. #define kPreemptiveThread        (1<<1)
  59.  
  60. /* Thread identifiers */
  61. typedef unsigned long            ThreadID;
  62. #define kNoThreadID                ((ThreadID) 0)
  63. #define kCurrentThreadID        ((ThreadID) 1)
  64. #define kApplicationThreadID    ((ThreadID) 2)
  65.  
  66. /* Options when creating a thread */
  67. typedef unsigned long            ThreadOptions;
  68. #define kNewSuspend                (1<<0)
  69. #define kUsePremadeThread        (1<<1)
  70. #define kCreateIfNeeded            (1<<2)
  71. #define kFPUNotNeeded            (1<<3)
  72.  
  73. /* Information supplied to the custom scheduler */
  74. typedef struct SchedulerInfoRec {
  75.     unsigned long    InfoRecSize;
  76.     ThreadID        CurrentThreadID;
  77.     ThreadID        SuggestedThreadID;
  78.     ThreadID        InterruptedCoopThreadID;
  79. } SchedulerInfoRec, *SchedulerInfoRecPtr;
  80.  
  81. /* Prototype for thread's entry (main) routine */
  82. typedef pascal void *            (ThreadEntryProc)(void *threadParam);
  83. typedef ThreadEntryProc            *ThreadEntryProcPtr;
  84.  
  85. /* Prototype for custom thread scheduler routine */
  86. typedef pascal ThreadID            (ThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
  87. typedef ThreadSchedulerProc        *ThreadSchedulerProcPtr;
  88.  
  89. /* Prototype for custom thread switcher routine */
  90. typedef pascal void                (ThreadSwitchProc)(ThreadID threadBeingSwitched, void *switchProcParam);
  91. typedef ThreadSwitchProc        *ThreadSwitchProcPtr;
  92.  
  93. /* Prototype for thread termination notification routine */
  94. typedef pascal void                (ThreadTerminationProc)(ThreadID threadTerminated, void *terminationProcParam);
  95. typedef ThreadTerminationProc    *ThreadTerminationProcPtr;
  96.  
  97. /* Prototype for debugger NewThread notification */
  98. typedef pascal void                    (DebuggerNewThreadProc)(ThreadID threadCreated);
  99. typedef DebuggerNewThreadProc        *DebuggerNewThreadProcPtr;
  100.  
  101. /* Prototype for debugger DisposeThread notification */
  102. typedef pascal void                    (DebuggerDisposeThreadProc)(ThreadID threadDeleted);
  103. typedef DebuggerDisposeThreadProc        *DebuggerDisposeThreadProcPtr;
  104.  
  105. /* Prototype for debugger schedule notification */
  106. typedef pascal ThreadID                (DebuggerThreadSchedulerProc)(SchedulerInfoRecPtr schedulerInfo);
  107. typedef DebuggerThreadSchedulerProc    *DebuggerThreadSchedulerProcPtr;
  108.  
  109. /* Errors */
  110. enum {
  111.     threadTooManyReqsErr    = -617,
  112.     threadNotFoundErr        = -618,
  113.     threadProtocolErr        = -619
  114. };
  115.  
  116. /* Thread Manager routines */
  117. pascal OSErr CreateThreadPool(ThreadStyle threadStyle, short numToCreate, Size stackSize)
  118.     = {0x303C,0x0501,0xABF2};
  119.  
  120. pascal OSErr GetFreeThreadCount(ThreadStyle threadStyle, short *freeCount)
  121.     = {0x303C,0x0402,0xABF2};
  122.  
  123. pascal OSErr GetDefaultThreadStackSize(ThreadStyle threadStyle, Size *stackSize)
  124.     = {0x303C,0x0413,0xABF2};
  125.  
  126. pascal OSErr ThreadCurrentStackSpace(ThreadID thread, unsigned long *freeStack)
  127.     = {0x303C,0x0414,0xABF2};
  128.  
  129. pascal OSErr NewThread(    ThreadStyle threadStyle,
  130.                         ThreadEntryProcPtr threadEntry,
  131.                         void *threadParam,
  132.                         Size stackSize,
  133.                         ThreadOptions options,
  134.                         void **threadResult,
  135.                         ThreadID *threadMade)
  136.     = {0x303C,0x0E03,0xABF2};
  137.  
  138. pascal OSErr DisposeThread(ThreadID threadToDump, void *threadResult, Boolean recycleThread)
  139.     = {0x303C,0x0504,0xABF2};
  140.  
  141. pascal OSErr YieldToThread(ThreadID suggestedThread)
  142.     = {0x303C,0x0205,0xABF2};
  143.  
  144. pascal OSErr YieldToAnyThread(void)
  145.     = {0x42A7,0x303C,0x0205,0xABF2};
  146.  
  147. pascal OSErr GetCurrentThread(ThreadID *currentThreadID)
  148.     = {0x303C,0x0206,0xABF2};
  149.  
  150. pascal OSErr GetThreadState(ThreadID threadToGet, ThreadState *threadState)
  151.     = {0x303C,0x0407,0xABF2};
  152.  
  153. pascal OSErr SetThreadState(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  154.     = {0x303C,0x0508,0xABF2};
  155.  
  156. pascal OSErr SetThreadStateEndCritical(ThreadID threadToSet, ThreadState newState, ThreadID suggestedThread)
  157.     = {0x303C,0x0512,0xABF2};
  158.  
  159. pascal OSErr SetThreadScheduler(ThreadSchedulerProcPtr threadScheduler)
  160.     = {0x303C,0x0209,0xABF2};
  161.  
  162. pascal OSErr SetThreadSwitcher(ThreadID thread, ThreadSwitchProcPtr threadSwitcher, void *switchProcParam, Boolean inOrOut)
  163.     = {0x303C,0x070A,0xABF2};
  164.  
  165. pascal OSErr SetThreadTerminator(ThreadID thread, ThreadTerminationProcPtr threadTerminator, void *terminationProcParam)
  166.     = {0x303C,0x0611,0xABF2};
  167.  
  168. pascal OSErr ThreadBeginCritical(void)
  169.     = {0x303C,0x000B,0xABF2};
  170.  
  171. pascal OSErr ThreadEndCritical(void)
  172.     = {0x303C,0x000C,0xABF2};
  173.  
  174. pascal OSErr SetDebuggerNotificationProcs (    DebuggerNewThreadProcPtr notifyNewThread,
  175.                                             DebuggerDisposeThreadProcPtr notifyDisposeThread,
  176.                                             DebuggerThreadSchedulerProcPtr notifyThreadScheduler)
  177.     = {0x303C,0x060D,0xABF2};
  178.  
  179. pascal OSErr GetThreadCurrentTaskRef (ThreadTaskRef *threadTRef)
  180.     = {0x303C,0x020E,0xABF2};
  181.  
  182. pascal OSErr GetThreadStateGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToGet, ThreadState *threadState)
  183.     = {0x303C,0x060F,0xABF2};
  184.  
  185. pascal OSErr SetThreadReadyGivenTaskRef (ThreadTaskRef threadTRef, ThreadID threadToSet)
  186.     = {0x303C,0x0410,0xABF2};
  187.  
  188.  
  189. #endif /* __THREADS__ */
  190.